package com.ifast.oupei.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ifast.common.base.BaseController;
import com.ifast.oupei.domain.SynthesisDO;
import com.ifast.oupei.service.SynthesisService;
import com.ifast.common.utils.Result;

/**
 * 
 * <pre>
 * 综合分析表
 * </pre>
 * 
 * <small> 2018-06-20 09:10:55 | Aron</small>
 */
@Controller
@RequestMapping("/oupei/synthesis")
public class SynthesisController extends BaseController {
	@Autowired
	private SynthesisService synthesisService;

	/**
	 * 综合分析页面
	 * @param turn
	 * @param id
	 * @param model
	 * @return
	 */
	@GetMapping("/add/{turn}/{id}")
	@RequiresPermissions("oupei:match:match")
	String add(@PathVariable(value = "turn") String turn, @PathVariable(value = "id") Integer id, Model model) {
		model.addAttribute("turn", turn);
		model.addAttribute("id", id);
		SynthesisDO synthesisDO = synthesisService
				.selectOne(new EntityWrapper<SynthesisDO>().where("league_id = {0}", id).andNew("turn = {0}", turn));
		String content = "";
		if(synthesisDO!=null)content=synthesisDO.getContent();
		model.addAttribute("content", content);//数据库中存在内容
		model.addAttribute("synthesisDO", synthesisDO);
		return "oupei/synthesis/add";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("oupei:match:match")
	public Result<String> save(SynthesisDO synthesis) {
		synthesisService.insertOrUpdate(synthesis);
		return Result.ok();
	}

}
